package com.deng.util
{
	import mx.controls.Alert;
	import mx.formatters.DateFormatter;
	
	public class DateTools
	{
		public function DateTools()
		{
		}
		public static function getTimeCode():String
		{
			return new Date().getTime().toString();
		}
		public static function getAllDate(phD:Date):String{
			var myDateFormatXQ:DateFormatter = new DateFormatter();
			myDateFormatXQ.formatString="YYYY-MM-DD HH:NN:SS";
			return myDateFormatXQ.format(phD);
//			return phD.fullYear+"年"+(phD.month+1)+"月"+phD.date+" "+phD.hours+":"+phD.minutes+":"+phD.seconds;
		}
		public static function getJustDate(phD:Date):String{
			var myDateFormatXQ:DateFormatter = new DateFormatter();
			myDateFormatXQ.formatString="YYYY-MM-DD";
			return myDateFormatXQ.format(phD);
//			return phD.fullYear+"年"+(phD.month+1)+"月"+phD.date+" "+phD.hours+":"+phD.minutes+":"+phD.seconds;
		}
		public static function getJustDate_CHS(phD:Date):String{
			var myDateFormatXQ:DateFormatter = new DateFormatter();
			myDateFormatXQ.formatString="YYYY年MM月DD日";
			return myDateFormatXQ.format(phD);
//			return phD.fullYear+"年"+(phD.month+1)+"月"+phD.date+" "+phD.hours+":"+phD.minutes+":"+phD.seconds;
		}
		public static function getAllDate_CHS(phD:Date):String{
			var myDateFormatXQ:DateFormatter = new DateFormatter();
			myDateFormatXQ.formatString="YYYY年MM月DD日HH点";
			return myDateFormatXQ.format(phD);
//			return phD.fullYear+"年"+(phD.month+1)+"月"+phD.date+" "+phD.hours+":"+phD.minutes+":"+phD.seconds;
		}
		public static function getAllDateWithSecond_CHS(phD:Date):String{
			return phD.getFullYear()+"年"+(phD.getMonth()+1)+"月"+phD.getDate()+"日 "+phD.getHours()+"点"+phD.getMinutes()+"分"+phD.getSeconds()+"秒";
//			return myDateFormatXQ.format(phD);
//			return phD.fullYear+"年"+(phD.month+1)+"月"+phD.date+" "+phD.hours+":"+phD.minutes+":"+phD.seconds;
		}
		public static function getDateByStrToFormat(str:String) :Date { 
			var dt:Date = new Date();
			var ar:Array = str.split("-");
			dt.setFullYear(new Number(ar[0]),new Number(ar[1]),new Number(ar[2]));
//			date.setMonth(ar[1] as Number);
//			date.setDate(ar[2] as Number);
//			Alert.show(ar[0]+" ... "+ar[1]+"   "+ar[2]);
//			Alert.show(date.toLocaleString());
			return dt;
		}
		public static function getYMByYM(str:String):String{
			var ar:Array = str.split("-");
			try{
				var y:int = new Number(ar[0]);
				var m:int = new Number(ar[1]);
				if(y > 1900 && y < 2200 && m>0 && m< 13){
					return y+"-"+m+"-1";
				}
			}catch(err:Error){
				Alert.show(err.getStackTrace());
			}
			return null;
		}
	}
}